<template>
  <el-table :data="things" style="width: %">
    <el-table-column label="课程名称" width="200">
      <template slot-scope="scope">
        <el-popover trigger="hover" placement="top">
          <p>课程编号: {{ scope.row.course.CourseId }}</p>
          <p>课程人数: {{ scope.row.course.courseName }}</p>
          <div slot="reference" class="name-wrapper">
            <el-tag size="medium">{{ scope.row.course.courseName }}</el-tag>
          </div>
        </el-popover>
      </template>
    </el-table-column>
    <el-table-column label="班级编号" width="150">
      <template slot-scope="scope">
        <el-popover trigger="hover" placement="top">
          <p>班级编号: {{ scope.row.course.classId }}</p>
          <p>班级人数: {{ scope.row.course.classNumber }}</p>
          <div slot="reference" class="name-wrapper">
            <el-tag size="medium">{{ scope.row.course.classId }}</el-tag>
          </div>
        </el-popover>
      </template>
    </el-table-column>
    <el-table-column label="教师姓名" width="150">
      <template slot-scope="scope">
        <el-popover trigger="hover" placement="top">
          <p>教师编号: {{ scope.row.course.teacherId }}</p>
          <p>教师姓名: {{ scope.row.teacherName }}</p>
          <div slot="reference" class="name-wrapper">
            <el-tag size="medium">{{ scope.row.teacherName }}</el-tag>
          </div>
        </el-popover>
      </template>
    </el-table-column>
    <el-table-column label="操作">
      <template slot-scope="scope">
        <el-button size="mini" @click="handleEdit(scope.row)">编辑</el-button>
        <el-button size="mini" type="danger" @click="handleDelete(scope.row)"
          >删除</el-button
        >
      </template>
    </el-table-column>
  </el-table>
</template>
  
<script>
import { serverAddress } from "../js/config";
import axios from "axios";
export default {
  name: "OneOfClass",
  props: ["things"],
  data() {
    return {
      loading: true,  
    };
  },
  methods: {
    handleEdit(row) {
      console.log(row);
      this.$emit("EditInformation", row);
    },
    handleDelete(row) {
      console.log(row);
      const result = confirm("是否确认删除此课程?");
      if (result) {
        console.log("用户确认删除");
        axios({
          /* url:`${serverAddress}/courseManage/delete`, */
          url: "https://mock.apifox.com/m2/3662090-0-default/143564257",
          method: "POST",
          data: {
            courseId:row.course.CourseId,
          }
        })
          .then((response) => {
            console.log(row.course.CourseId);
            if (response.data.code === 1) {
              alert("删除成功！");
              this.$parent.refresh();
              console.log(response.data);
            } else {
              console.log(response.data.msg);
            }
          })
          .catch((error) => {
            console.log("网络错误,删除失败");
          });
      } else {
        console.log("用户取消删除");
      }
    },
  },
};
</script>